What is micromark-factory-space?
The micromark-factory-space package is a utility for handling spaces in the micromark ecosystem, which is a tool for parsing and compiling markdown. It provides functions to handle spaces, tabs, and line endings in markdown documents.
What are micromark-factory-space's main functionalities?
Handling spaces
This feature allows you to handle spaces in markdown documents. The factorySpace function is used to create a tokenizer that processes spaces.
const { factorySpace } = require('micromark-factory-space');
const tokenizer = {
tokenize: function (effects, ok, nok) {
return factorySpace(effects, ok, 'space');
}
};
Handling tabs
This feature allows you to handle tabs in markdown documents. The factorySpace function is used to create a tokenizer that processes tabs.
const { factorySpace } = require('micromark-factory-space');
const tokenizer = {
tokenize: function (effects, ok, nok) {
return factorySpace(effects, ok, 'tab');
}
};
Handling line endings
This feature allows you to handle line endings in markdown documents. The factorySpace function is used to create a tokenizer that processes line endings.
const { factorySpace } = require('micromark-factory-space');
const tokenizer = {
tokenize: function (effects, ok, nok) {
return factorySpace(effects, ok, 'lineEnding');
}
};
Other packages similar to micromark-factory-space
micromark
Micromark is a comprehensive markdown parser that includes various utilities for handling markdown syntax, including spaces, tabs, and line endings. It is more feature-rich compared to micromark-factory-space, which focuses specifically on space handling.
remark
Remark is a markdown processor built on the unified framework. It provides extensive plugins and utilities for parsing, transforming, and compiling markdown. While it offers broader functionality, it can be more complex to use compared to the focused micromark-factory-space.
markdown-it
Markdown-it is a fast and flexible markdown parser that supports plugins for extended functionality. It provides similar capabilities for handling spaces, tabs, and line endings but is designed to be more extensible and customizable.
micromark-factory-space
micromark factory to parse markdown space (found in lots
of places).
Contents
What is this?
This package exposes states to parse spaces and/or tabs.
When should I use this?
This package is useful when you are making your own micromark extensions.
Install
This package is ESM only.
In Node.js (version 16+), install with npm:
npm install micromark-factory-space
In Deno with esm.sh
:
import {factorySpace} from 'https://esm.sh/micromark-factory-space@1'
In browsers with esm.sh
:
<script type="module">
import {factorySpace} from 'https://esm.sh/micromark-factory-space@1?bundle'
</script>
Use
import {factorySpace} from 'micromark-factory-space'
import {codes} from 'micromark-util-symbol/codes'
import {types} from 'micromark-util-symbol/types'
function tokenizeCodeFenced(effects, ok, nok) {
return start
function info(code) {
if (code === codes.eof || markdownLineEndingOrSpace(code)) {
effects.exit(types.chunkString)
effects.exit(types.codeFencedFenceInfo)
return factorySpace(effects, infoAfter, types.whitespace)(code)
}
if (code === codes.graveAccent && code === marker) return nok(code)
effects.consume(code)
return info
}
}
API
This module exports the identifier factorySpace
.
There is no default export.
factorySpace(…)
Parse spaces and tabs.
There is no nok
parameter:
- spaces in markdown are often optional, in which case this factory can be
used and
ok
will be switched to whether spaces were found or not - one line ending or space can be detected with
markdownSpace(code)
right
before using factorySpace
Examples
Where ␉
represents a tab (plus how much it expands) and ␠
represents a
single space.
␉
␠␠␠␠
␉␠
Parameters
effects
(Effects
)
— contextok
(State
)
— state switched to when successfultype
(string
)
— type (' \t'
)max
(number
, default: Infinity
)
— max (exclusive)
Returns
Start state (State
).
Types
This package is fully typed with TypeScript.
It exports no additional types.
Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 16+.
Our projects sometimes work with older versions, but this is not guaranteed.
This package works with micromark
version 3+.
Security
This package is safe.
See security.md
in micromark/.github
for how to
submit a security report.
Contribute
See contributing.md
in micromark/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct.
By interacting with this repository, organisation, or community you agree to
abide by its terms.
License
MIT © Titus Wormer